package com.ruoyi.info.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.info.domain.ProductType;
import com.ruoyi.info.service.IProductTypeService;
import com.ruoyi.common.utils.poi.ExcelUtil;

/**
 * 产品类型Controller
 * 
 * @author wangshi
 * @date 2023-06-10
 */
@RestController
@RequestMapping("/info/productType")
public class ProductTypeController extends BaseController
{
    @Autowired
    private IProductTypeService productTypeService;

    /**
     * 查询产品类型列表
     */
    @PreAuthorize("@ss.hasPermi('info:productType:list')")
    @GetMapping("/list")
    public AjaxResult list(ProductType productType)
    {
        List<ProductType> list = productTypeService.selectProductTypeList(productType);
        return success(list);
    }

    /**
     * 导出产品类型列表
     */
    @PreAuthorize("@ss.hasPermi('info:productType:export')")
    @Log(title = "产品类型", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ProductType productType)
    {
        List<ProductType> list = productTypeService.selectProductTypeList(productType);
        ExcelUtil<ProductType> util = new ExcelUtil<ProductType>(ProductType.class);
        util.exportExcel(response, list, "产品类型数据");
    }

    /**
     * 获取产品类型详细信息
     */
    @PreAuthorize("@ss.hasPermi('info:productType:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(productTypeService.selectProductTypeById(id));
    }

    /**
     * 新增产品类型
     */
    @PreAuthorize("@ss.hasPermi('info:productType:add')")
    @Log(title = "产品类型", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ProductType productType)
    {
        return toAjax(productTypeService.insertProductType(productType));
    }

    /**
     * 修改产品类型
     */
    @PreAuthorize("@ss.hasPermi('info:productType:edit')")
    @Log(title = "产品类型", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ProductType productType)
    {
        return toAjax(productTypeService.updateProductType(productType));
    }

    /**
     * 删除产品类型
     */
    @PreAuthorize("@ss.hasPermi('info:productType:remove')")
    @Log(title = "产品类型", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(productTypeService.deleteProductTypeByIds(ids));
    }
}
